package com.moxi.mogublog.sms.controller;

import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.moxi.mogublog.sms.global.SysConf;
import com.moxi.mogublog.sms.util.SmsUtil;
import com.moxi.mogublog.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * description
 *
 * @author JackLi
 * @date 2020-05-28 下午9:52
 */
@RestController
@RequestMapping(value = "/sms")
public class SmsController {

    @Autowired
    private SmsUtil smsUtil;

    /**
     * 查看短信发送记录和发送状态
     *
     * @param queryMap 包含 mobile、bizId
     * @return
     */
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    public String querySendSmsDetails(@RequestBody Map<String, String> queryMap) {
        String mobile = queryMap.get("mobile");
        String bizId = queryMap.get("bizId");
        try {
            QuerySendDetailsResponse sendDetails = smsUtil.querySendDetails(mobile, bizId);
            Map<String, Object> retMap = new HashMap<String, Object>(SysConf.NUM_ONE);
            retMap.put("smsSendDetails", sendDetails);
            return ResultUtil.result(SysConf.SUCCESS, retMap);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return ResultUtil.result(SysConf.ERROR, null);
    }

}
